package com.goods.controller.business;

import com.goods.business.service.ConsumerServices;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ConsumerVO;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：MJS
 * @date ：Created in 2021/6/10  9:00
 * @description：TODO
 */
@RestController
@RequestMapping("/business/consumer")
public class ConsumerController {
    @Autowired
    private ConsumerServices consumerServices;
    //查询物资去处
    @ApiOperation(value = "物资来源列表", notes = "模糊查询物资去处列表")
    @GetMapping("/findConsumerList")
    public ResponseBean<PageVO<ConsumerVO>>findConsumerList(
                                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                @RequestParam(value = "pageSize",defaultValue = "6") Integer pageSize,
                                                ConsumerVO consumerVO){
        PageVO<ConsumerVO>consumerList=consumerServices.findConsumerList(pageNum,pageSize,consumerVO);
        return ResponseBean.success(consumerList);
    }
    //添加物资去处
    @ApiOperation(value = "添加物资去处", notes = "添加物资去处信息")
    @PostMapping("/add")
    public ResponseBean add(@RequestBody ConsumerVO consumerVO){
        consumerServices.add(consumerVO);
        return ResponseBean.success();
    }
    //物资来源回显
    @ApiOperation(value = "编辑物资去处", notes = "获取物资去处的详情，编辑物资去处信息")
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        ConsumerVO consumerVO=consumerServices.edit(id);
        return ResponseBean.success(consumerVO);
    }
    //修改物资来源信息
    @ApiOperation(value = "更新物资去处", notes = "更新物资去处信息")
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,
                               @RequestBody ConsumerVO consumerVO){
        consumerServices.update(id,consumerVO);
        return ResponseBean.success();
    }

    //删除物资来源
    @ApiOperation(value = "删除物资去处", notes = "删除物资去处信息")
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        consumerServices.delete(id);
        return ResponseBean.success();
    }

    //查询全部
    @GetMapping("/findAll")
    public ResponseBean findAll(){
        List<ConsumerVO>consumerVOList=consumerServices.findAll();
    return ResponseBean.success(consumerVOList);
    }
}
